//
//  DHS2_SearchAll_BrandsCell.m
//  Dresshere
//
//  Created by ZhangPeng on 2018/6/7.
//  Copyright © 2018年 张朋. All rights reserved.
//

#import "DHS2_SearchAll_BrandsCell.h"
#import "DHS2_SearchView_All_BrandCell.h"
#import "DHS2_BrandViewController.h"

@interface DHS2_SearchAll_BrandsCell()<UITableViewDelegate, UITableViewDataSource>

@property (strong, nonatomic) NSArray *arr;

@end

@implementation DHS2_SearchAll_BrandsCell

- (void)awakeFromNib {
    [super awakeFromNib];
    
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"DHS2_SearchView_All_BrandCell" bundle:nil] forCellReuseIdentifier:kDHS2_SearchView_All_BrandCell];
}

- (IBAction)allAction:(id)sender {
    [self routerEventWithName:@"brand_all" userInfo:nil];
}

- (void)updateWithArr:(NSArray *)arr{
    self.arr = arr;
    [self.tableView reloadData];
}

- (NSArray *)arr{
    if (!_arr) {
        _arr = [NSArray array];
    }
    return _arr;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

#pragma mark - UITableViewDataSource and UITableViewDelegate
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.arr.count;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 65;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    DHS2_SearchView_All_BrandCell *cell = [tableView dequeueReusableCellWithIdentifier:kDHS2_SearchView_All_BrandCell forIndexPath:indexPath];
    NSDictionary *dic = [self.arr objectAtIndex:indexPath.row];
    [cell.coverImgView dh_setImageURLString:[dic objectForKey:@"logo"]];
    cell.nameLabel.text = [dic objectForKey:@"name"];
    cell.countLabel.text = [NSString stringWithFormat:@"%@件衣服",[dic objectForKey:@"product_count"]];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    NSDictionary *dic = [self.arr objectAtIndex:indexPath.row];
    DHS2_BrandViewController *brandController = [[DHS2_BrandViewController alloc] initWithBrandID:[dic objectForKey:@"_id"]];
    brandController.hidesBottomBarWhenPushed = YES;
    [self.viewController.navigationController pushViewController:brandController animated:YES];
}

@end
